﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NHibernate;
using SportWebShop.Data.Entities;

namespace SportWebShop.Controllers
{
	public class HomeController : Controller
	{
		//
		// GET: /Home/

		private readonly ISessionFactory sessionFactory;

		public HomeController(ISessionFactory sessionFactory)
		{
			this.sessionFactory = sessionFactory;
		}

		public ActionResult Index()
		{
			var cat = new Category { Name = "abc" };
			var product = new Product { Category = cat, Name = "Ball", Description = "Ball for playing football", Price = 12 };
			using (var session = sessionFactory.OpenSession())
			{
				using (var transaction = session.BeginTransaction())
				{
					session.SaveOrUpdate(product);
					transaction.Commit();
				}
			}
			return View();
		}

	}
}
